﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using Calvin.Utilities.Excel操作;
using System.Data;
using NPOI;
using NPOI.HPSF;
using NPOI.HSSF;
using NPOI.HSSF.UserModel;
using NPOI.POIFS;
using NPOI.Util;
using NPOI.HSSF.Util;
using NPOI.HSSF.Extractor;
using System.Web.UI.HtmlControls;
using NPOI.SS.UserModel;
using NPOI.HSSF.Record.CF;
using NPOI.SS.Util;


namespace testweb.Excel操作
{
    public partial class createExcelWithHeader : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            FileStream ss = new FileStream(Server.MapPath("2014年预征数据备份-20140529.xls"), FileMode.Open,FileAccess.ReadWrite);

            DataTable ssss = ExcelUtilityNoCom.RenderDataTableFromExcel(ss, 0, 0, true);

            string path = Server.MapPath(DateTime.Now.Ticks + ".xls");
            HSSFWorkbook book = new HSSFWorkbook();
            book.CreateSheet();
            ISheet sheet = book.GetSheetAt(0);
            ICellStyle headerStyle = book.CreateCellStyle();
            headerStyle.Alignment = HorizontalAlignment.Center;
            IFont headerFont=book.CreateFont();
            headerFont.FontName="宋体";
            
            headerFont.Boldweight = (short)NPOI.SS.UserModel.FontBoldWeight.Bold;
            headerFont.FontHeightInPoints = 18;
            headerStyle.SetFont(headerFont);
            IRow row = sheet.CreateRow(0);
            ICell cell = row.CreateCell(0);
            cell.SetCellValue("欧某标题");
            cell.CellStyle = headerStyle;
            ExcelUtilityNoCom.MergeCell(book, 0, 0, 0, ssss.Columns.Count - 1);
            //ExcelUtilityNoCom.SetCellFont(cell, book, "黑体", 24,new HSSFColor.Blue(), FontUnderlineType.Double);
            //ExcelUtilityNoCom.SetCellBorder(cell, book, NPOI.SS.UserModel.BorderStyle.Thin);

            ExcelUtilityNoCom.RenderDataTableToWorkBook(ssss, book, 1, 1, 0, true);
            ExcelUtilityNoCom.WorkBookToFile(book, path);
          

       
        }
    }
}